package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-04-28 23:08
 */
public class Q80 {
    public int removeDuplicates(int[] nums) {
        if(nums == null || nums.length == 0) {
            return 0;
        }

        int i = 0;
        int cnt = 1;
        for (int j = 1; j < nums.length; j++) {
            if(nums[j] == nums[j - 1]) {
                cnt++;
            } else {
                cnt = 1;
            }

            if(cnt <= 2) {
                i++;
                nums[i] = nums[j];
            }
        }

        return i + 1;
    }
}
